package com.acme.bankapp.domain.bank;

import java.io.Serializable;

@SuppressWarnings("serial")
public class Bank implements Serializable {
	
	private Client[] clients;
	private ClientRegistrationListener [] listeners;
	
	public Bank() {
		clients = new Client[10];
	}

	public Bank(ClientRegistrationListener[] listeners) {
		clients = new Client[10];
		this.listeners = listeners;
	}
	
	public void addClient(Client client)
	{
		for (int i = 0; i < clients.length; i++)
		{
			if (clients[i] == null)
			{
				clients[i] = client;
				if (listeners != null) {
					for (ClientRegistrationListener listener: listeners) {
						if (listener != null) listener.onClientAdded(client);
					}
				}
				return;
			}
		}
	}
	
	public Client getClient(int num)
	{
		return clients[num];
	}
	
	public int numClients() {
		for (int i = 0; i < clients.length; i++)
		{
			if (clients[i] == null)
			{
				return i;
			}
		} 
		return clients.length;
	}
}
